/**
 * Licensed to Open-Ones Group under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Open-Ones Group licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a
 * copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package openones.ipresenter.android.blo;

/**
 * This class is used to convert collapsed time to formated time hh:mm:ss.
 * @author OOG member
 */
public final class TimeSupport {
    
    /**
     * There are 3600 seconds in an hour.
     */
    private static final int MAX_SECONDS_IN_HOUR = 3600;
    
    /**
     * There are 60 seconds in a minute.
     */
    private static final int MAX_SECONDS_IN_MINUTE = 60;
    
    /**
     * Private constructor.
     */
    private TimeSupport() {
        
    }
    
    /**
     * Convert time to hh:mm:ss.
     * @param time The collapsed time to be converted.
     * @return Formatted time in hh:mm:ss
     */
    public static String format(int time) {
        int hour = 0;
        int minute = 0;
        int second = 0;
        int temp = time;
        
        if (temp / MAX_SECONDS_IN_HOUR > 0) {
            hour = temp / MAX_SECONDS_IN_HOUR;
            temp = temp % MAX_SECONDS_IN_HOUR;
        }
        
        if (temp / MAX_SECONDS_IN_MINUTE > 0) {
            minute = temp / MAX_SECONDS_IN_MINUTE;
            temp = temp % MAX_SECONDS_IN_MINUTE;
        }
        
        second = temp;
        if (second < 0) {
            second = 0;
        }
            

        return String.format(String.format("%02d:%02d:%02d", hour, minute, second));
    }
}
